package com.tanran.taolijin.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tanran.taolijin.model.TaobaoAccount;
import com.tanran.taolijin.model.TaobaoGood;
import com.tanran.taolijin.repository.TaobaoAccountRepository;
import com.tanran.taolijin.repository.TaobaoGoodRepository;
import com.tanran.taolijin.service.TaobaoService;
import com.tanran.taolijin.util.*;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * Created by Enzo Cotter on 2019/10/22.
 */
@Service
@Slf4j
public class TaobaoServiceImpl implements TaobaoService {

    @Value("${interface.ip}")
    private  String ip;
    @Value("${interface.port}")
    private  String port;

    @Autowired
    private TaobaoAccountRepository taobaoAccountRepository;
    @Autowired
    private TaobaoGoodRepository taobaoGoodRepository;

    @Override
    public Result loginState(TaobaoAccount taobaoAccount) {
        String nickName = loginStateApi(taobaoAccount);
        sendMessage("12313");
        return nickName==""?Result.noLogin(): Result.ok(nickName);
    }

    @Override
    public Result parse(String mlOrUrl) {
        TaobaoGood taobaoGood=new TaobaoGood();
        if(mlOrUrl.startsWith("￥") && mlOrUrl.endsWith("￥")){
             String goodUrl = parseMlApi(mlOrUrl);
             if(goodUrl==""){
                 goodUrl = parseMl2Api(new TaobaoAccount(),mlOrUrl);
             }
             taobaoGood = parseUrlApi(goodUrl);
        }
        if(mlOrUrl.startsWith("http") || mlOrUrl.indexOf("taolijin")!=-1){
             taobaoGood=parseUrlApi(mlOrUrl);
        }
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("data",taobaoGood);
        return Result.ok(hashMap);
    }



    @Override
    public Result createQr() {
        TaobaoAccount taobaoAccount = createQrApi();
        HashMap<String, Object> taobaoAccountMap = new HashMap<>();
        taobaoAccountMap.put("data",taobaoAccount);
        return Result.ok(taobaoAccountMap);
    }

    @Override
    public Result checkQr(TaobaoAccount taobaoAccount) {
        String result = checkQrApi(taobaoAccount);
        return Result.ok(result);
    }

    @Override
    public Result loginQr(TaobaoAccount taobaoAccount) {
        taobaoAccount = loginQrApi(taobaoAccount);
        if(StringUtils.isEmpty(taobaoAccount.getuId())){
            return Result.error("登陆失败");
        }
        return Result.ok(taobaoAccount.getNickName()+"登陆成功");
    }

    @Override
    public Result task(String mlOrUrl) {
        //第一步  先解析出淘宝信息
        TaobaoGood taobaoGood=new TaobaoGood();
        String goodUrl="";
        if(mlOrUrl.startsWith("￥") && mlOrUrl.endsWith("￥")){
            goodUrl = parseMlApi(mlOrUrl);
            if(StringUtils.isEmpty(goodUrl)){
                goodUrl = parseMl2Api(new TaobaoAccount(),mlOrUrl);
            }
        }
        if(!goodUrl.startsWith("http") || goodUrl.indexOf("taolijin")==-1){
            log.info("领取地址非淘礼金地址跳过,地址为"+goodUrl);
            return Result.error("领取地址非淘礼金地址跳过,地址为"+goodUrl);
        }
        taobaoGood=parseUrlApi(goodUrl);
        if(Objects.isNull(taobaoGood)){
            log.info("地址解析商品失败");
            return Result.error("地址解析商品失败");
        }
        //从数据库拿数据
        List<TaobaoAccount> taobaoAccounts = taobaoAccountRepository.findAll();
        for (TaobaoAccount taobaoAccount : taobaoAccounts) {
            String nickName = loginStateApi(taobaoAccount);
             if(StringUtils.isEmpty(nickName)){
                 //发送通知消息
                 if(!StringUtils.isEmpty(taobaoAccount.getNoticeChat())){
                     sendMessage("unLine||"+taobaoAccount.getNoticeChat());
                 }
                 log.info("淘宝用户名为{}已掉线",taobaoAccount.getNickName());
                 continue;
             }
             //主要工作
            work(taobaoAccount,taobaoGood,mlOrUrl);
        }
        return Result.ok("成功");
    }

    private void work(TaobaoAccount taobaoAccount,TaobaoGood taobaoGood,String mlOrUrl){
        String drawResult = drawApi(taobaoAccount, taobaoGood);
        log.info("淘宝用户名为{},淘礼金"+drawResult,taobaoAccount.getNickName());
        if(!"中奖了".equals(drawResult)){
            return ;
        }
        if(StringUtils.isEmpty(taobaoGood.getCouponKey())){
            taobaoGoodRepository.save(taobaoGood);
            //调用接口发送成功消息
            if(!StringUtils.isEmpty(taobaoAccount.getNoticeChat())){
                sendMessage("success||"+taobaoAccount.getNoticeChat()+"||"+taobaoGood.getTitle()
                        +"||"+taobaoGood.getRightsFace() +"||"+taobaoGood.getAmount()
                        +"||"+taobaoGood.getDiscountPrice()+"||"+mlOrUrl);
            }
            return;
        }
        String couponResult = couponApi(taobaoAccount, taobaoGood);
        log.info("淘宝用户名为{},优惠卷"+couponResult,taobaoAccount.getNickName());
        if("领取成功".equals(couponResult)){
            taobaoGoodRepository.save(taobaoGood);
            //调用接口发送成功消息
            if(!StringUtils.isEmpty(taobaoAccount.getNoticeChat())){
                sendMessage("success||"+taobaoAccount.getNoticeChat()+"||"+taobaoGood.getTitle()
                        +"||"+taobaoGood.getRightsFace() +"||"+taobaoGood.getAmount()
                        +"||"+taobaoGood.getDiscountPrice()+"||"+mlOrUrl);
            }
            return ;
        }
    }


    //解析密令的api接口
    private String parseMlApi(String ml){
        String goodUrl="";
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("passwordContent",ml);
            String data=jsonObject.toJSONString();
            System.out.println(data);
            String url="https://api.m.taobao.com/gw/mtop.taobao.sharepassword.querypassword/1.0/?data="+URLEncoder.encode(data,"UTF-8");
            String result= OkHttpUtils.postForm(url, TaobaoApi.createHeader(),String.class);
            goodUrl= JsonUtil.getJsonValue(result,"data.url");
        }catch (Exception e){
            e.printStackTrace();
            log.error("发生错误,错误信息为{}",e.getMessage());
        }
        return goodUrl;
    }
    //解析密令的api接口
    private String parseMl2Api(TaobaoAccount taobaoAccount,String ml){
        String goodResult="";
        String goodUrl="";
        String cookiesNew="";
        for (int i = 0; i < 3; i++) {
            try {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("password",ml);
                String time=Long.toString(LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
                String data=String.format("appKey=%s&api=%s&v=%s&data=%s&t=%s&sign=%s","12574478","com.taobao.redbull.getpassworddetail","1.0",
                        URLEncoder.encode(jsonObject.toJSONString(),"UTF-8"),time
                        ,TaobaoApi.createSign(taobaoAccount.getmH5Tk(),time,"12574478",jsonObject.toJSONString())
                );
                String url="https://api.m.taobao.com/h5/com.taobao.redbull.getpassworddetail/1.0/?"+data;
                HashMap<String, String> requestHeaders = new HashMap<>();
                requestHeaders.put("Cookie",taobaoAccount.getCookies());
                requestHeaders.put("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36");
                Response response = OkHttpUtils.postForm(url, requestHeaders, new HashMap<>());
                if(response.isSuccessful()){
                    goodResult =response.body().string();
                    String[] responseHeaders = response.headers().toString().split("\n");
                    StringBuilder cookieNew = new StringBuilder();
                    for (String header : responseHeaders) {
                        if(header.startsWith("Set-Cookie")){
                            cookieNew.append(";");
                            cookieNew.append(header.substring(header.indexOf(":")+1,header.indexOf(";")));
                            cookieNew.append(";");
                        }
                    }
                    taobaoAccount.setCookies(cookieNew.toString());
                }
                System.out.println(goodResult);
                goodUrl= JsonUtil.getJsonValue(goodResult,"data.url");
            }catch (Exception e){
                e.printStackTrace();
                log.error("发生错误,错误信息为{}",e.getMessage());
            }
            if(goodResult.indexOf("url")!=-1) break;
        }
        return JsonUtil.getJsonValue(goodResult,"data.url");
    }
    //解析url的api接口
    private TaobaoGood parseUrlApi(String goodUrlUrl){
        TaobaoGood taobaoGood = new TaobaoGood();
        try {
            String eh = TextUtil.getSubString(goodUrlUrl+"&","eh=","&");
            if(eh==""){
                return new TaobaoGood();
            }
            String activityId = TextUtil.getSubString(goodUrlUrl+"&","activityId=","&");
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("eh",eh);
            jsonObject.put("activityId",activityId);
            jsonObject.put("isMobile","true");
            String data=jsonObject.toJSONString();
            String url="https://api.m.taobao.com/gw/mtop.alimama.vegas.center.flb.coupon.query/1.0/?data="+URLEncoder.encode(data,"UTF-8");
            String result= OkHttpUtils.postForm(url, TaobaoApi.createHeader(),String.class);
            System.out.println(result);
            taobaoGood.setTitle(JsonUtil.getJsonValue(result,"data.couponItem.title"));
            taobaoGood.setClickUrl(JsonUtil.getJsonValue(result,"data.couponItem.clickUrl"));
            taobaoGood.setEStr(TextUtil.getSubString(taobaoGood.getClickUrl(),"e=","&union_lens"));
            taobaoGood.setPid(JsonUtil.getJsonValue(result,"data.rightsInstance.pid"));
            taobaoGood.setEhStr(eh);
            taobaoGood.setDiscountPrice(JsonUtil.getJsonValue(result,"data.couponItem.discountPrice"));
            taobaoGood.setAmount(JsonUtil.getJsonValue(result,"data.coupon.amount"));
            taobaoGood.setCouponKey(JsonUtil.getJsonValue(result,"data.coupon.couponKey"));
            taobaoGood.setRightsFace(JsonUtil.getJsonValue(result,"data.rightsInstance.rightsFace"));
            taobaoGood.setItemId(JsonUtil.getJsonValue(result,"data.couponItem.itemId"));
            taobaoGood.setFinalPrice(JsonUtil.getJsonValue(result,"data.couponItem.finalPrice"));
            taobaoGood.setRightsNum(JsonUtil.getJsonValue(result,"data.rightsInstance.rightsNum"));
        }catch (Exception e){
            e.printStackTrace();
            log.error("发生错误,错误信息为{}",e.getMessage());
        }
        return taobaoGood;
    }


    //登陆状态判断的api接口
    private String loginStateApi(TaobaoAccount taobaoAccount){
        String nick="";
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("isSec",0);
            String data=jsonObject.toJSONString();
            System.out.println(data);
            String url="https://api.m.taobao.com/gw/mtop.user.getusersimple/1.0/?data="+URLEncoder.encode(data,"UTF-8");
            Map<String, String> header = TaobaoApi.createHeader(taobaoAccount.getsId(), taobaoAccount.getuId());
            String result= OkHttpUtils.postForm(url, header,String.class);
            System.out.println(result);
            nick= JsonUtil.getJsonValue(result,"data.nick");
        }catch (Exception e){
            e.printStackTrace();
            log.error("发生错误,错误信息为{}",e.getMessage());
        }
        return nick;
    }
    //抽奖的api接口
    private String drawApi(TaobaoAccount taobaoAccount,TaobaoGood taobaoGood){
        if(taobaoAccount==null || taobaoGood==null){
            return "";
        }
         String drawResult = "";
         String cookiesNew = "";
        for (int i = 0; i < 3; i++) {
            try {
                JSONObject extend = new JSONObject();
                extend.put("e",taobaoGood.getEStr());
                extend.put("itemId",taobaoGood.getItemId());
                extend.put("rightsFace",taobaoGood.getRightsFace());
                extend.put("scence","wap");
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("eh",taobaoGood.getEhStr());
                jsonObject.put("pid",taobaoGood.getPid());
                jsonObject.put("asac","1A18912HD87JTTJQQI1QKJ");
                jsonObject.put("extend",extend.toJSONString());
                String time=Long.toString(LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
                String data=String.format("jsv=%s&appKey=%s&t=%s&api=%s&v=%s&AntiCreep=%s&AntiFlood=%s&ecode=%s&dataType=%s&data=%s&sign=%s",
                        "2.3.16","12574478",time,
                        "mtop.alimama.vegas.draw","1.0","true","true","0","jsonp",URLEncoder.encode(jsonObject.toJSONString(),"UTF-8")
                        ,TaobaoApi.createSign(taobaoAccount.getmH5Tk(),time,"12574478",jsonObject.toJSONString())
                );
                String url="https://acs.m.taobao.com/h5/mtop.alimama.vegas.draw/1.0/?"+data;
                Map<String, String> requestHeaders = new HashMap<>();
                requestHeaders.put("Cookie",taobaoAccount.getCookies());
                requestHeaders.put("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36");
                Response response = OkHttpUtils.postForm(url, requestHeaders, new HashMap<>());
                if(response.isSuccessful()){
                    drawResult =response.body().string();
                    String[] responseHeaders = response.headers().toString().split("\n");
                    StringBuilder cookieNew = new StringBuilder();
                    for (String header : responseHeaders) {
                        if(header.startsWith("Set-Cookie")){
                            cookieNew.append(";");
                            cookieNew.append(header.substring(header.indexOf(":")+1,header.indexOf(";")));
                            cookieNew.append(";");
                        }
                    }
                    cookiesNew=cookieNew.toString();
                    taobaoAccount.setCookies(taobaoAccount.getCookies()+cookiesNew);
                }
            }catch (Exception e){
                e.printStackTrace();
                log.error("发生错误,错误信息为{}",e.getMessage());
            }
            if(drawResult.indexOf("drawRetDesc")!=-1) break;
        }
        //{"api":"mtop.alimama.vegas.draw","data":{"drawRetCode":"1","drawRetDesc":"未中奖","drawRetSubCode":"34","extra":{"traceId":"0b5116dc15718184080068602eec01"}},"ret":["SUCCESS::接口调用成功"],"v":"1.0"}
        return StringUtils.isEmpty(JsonUtil.getJsonValue(drawResult,"data.drawRetDesc"))?"领取失败":JsonUtil.getJsonValue(drawResult,"data.drawRetDesc");
       // return drawResult;
    }
    //优惠卷接口
    private String couponApi(TaobaoAccount taobaoAccount,TaobaoGood taobaoGood){
        if(taobaoAccount==null || taobaoGood==null){
            return "";
        }
        String couponResult = "";
            try {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("couponKey",taobaoGood.getCouponKey());
                jsonObject.put("asac","1A17621S4VF9XKFZ9JX5X7");
                String time=Long.toString(LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
                String data=String.format("jsv=%s&appKey=%s&t=%s&api=%s&v=%s&AntiCreep=%s&AntiFlood=%s&ecode=%s&dataType=%s&data=%s&sign=%s",
                        "2.3.16","12574478",time,
                        "mtop.alimama.union.hsf.app.coupon.apply","1.0","true","true","0","jsonp",URLEncoder.encode(jsonObject.toJSONString(),"UTF-8")
                        ,TaobaoApi.createSign(taobaoAccount.getmH5Tk(),time,"12574478",jsonObject.toJSONString())
                );
                String url="https://acs.m.taobao.com/h5/mtop.alimama.union.hsf.app.coupon.apply/1.0/?"+data;
                Map<String, String> requestHeader = new HashMap<>();
                requestHeader.put("Cookie",taobaoAccount.getCookies());
                requestHeader.put("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36");
                couponResult = OkHttpUtils.postForm(url, requestHeader, String.class);
            }catch (Exception e){
                e.printStackTrace();
                log.error("发生错误,错误信息为{}",e.getMessage());
            }
        return StringUtils.isEmpty(JsonUtil.getJsonValue(couponResult,"data.result.coupon.msg"))?"领取成功":JsonUtil.getJsonValue(couponResult,"data.result.coupon.msg");
    }
    //二维码地址接口获取
    private TaobaoAccount createQrApi(){
        TaobaoAccount taobaoAccount = new TaobaoAccount();
        try {
            String url="https://qrlogin.taobao.com/qrcodelogin/generateNoLoginQRCode.do?lt=m";
            Map<String, String> requestHeaders = TaobaoApi.createHeader();
            Response response = OkHttpUtils.postForm(url, requestHeaders, new HashMap<>());
            if(response.isSuccessful()){
                String qrResult =response.body().string();
                String[] headers = response.headers().toString().split("\n");
                StringBuilder cookieNew = new StringBuilder();
                for (String header : headers) {
                    if(header.startsWith("Set-Cookie")){
                        cookieNew.append(";");
                        cookieNew.append(header.substring(header.indexOf(":")+1,header.indexOf(";")));
                        cookieNew.append(";");
                    }
                }
                if(qrResult.indexOf("true")!=-1){
                    taobaoAccount.setCookies(cookieNew.toString());
                    taobaoAccount.setQrUrl(JsonUtil.getJsonValue(qrResult,"url"));
                    taobaoAccount.setToken(JsonUtil.getJsonValue(qrResult,"at"));
                    taobaoAccount.setTime(JsonUtil.getJsonValue(qrResult,"t"));
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            log.error("发生错误,错误信息为{}",e.getMessage());
        }
        return taobaoAccount;
    }

    //二维码检测
    private String checkQrApi(TaobaoAccount taobaoAccount){
        String checkQrResult="";
        try {
            String url="https://api.m.taobao.com/gw/mtop.taobao.havana.mlogin.qrcodelogin/1.0/";
            Map<String, String> requestHeaders = TaobaoApi.createHeader();
            requestHeaders.put("Cookie",taobaoAccount.getCookies());
            JSONObject tokenInfo = new JSONObject();
            tokenInfo.put("appName","23039499");
            tokenInfo.put("token",taobaoAccount.getToken());
            tokenInfo.put("t",taobaoAccount.getTime());
            tokenInfo.put("sdkVersion","a_1.5.1-std");
            tokenInfo.put("clientIp","10.0.8.1");
            tokenInfo.put("site","0");
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("tokenInfo",tokenInfo.toJSONString());
            jsonObject.put("riskControlInfo","{}");
            jsonObject.put("ext","{}");
            checkQrResult = OkHttpUtils.postForm(url+"?data="+URLEncoder.encode(jsonObject.toJSONString(),"UTF-8"), requestHeaders, String.class);

        }catch (Exception e){
            e.printStackTrace();
            log.error("发生错误,错误信息为{}",e.getMessage());
        }
        return  checkQrResult;
    }

    //登陆
    private TaobaoAccount loginQrApi(TaobaoAccount taobaoAccount){
        try {
            String url="https://api.m.taobao.com/gw/mtop.com.taobao.mloginService.appOldAutoLogin/1.0/";
            Map<String, String> requestHeaders = TaobaoApi.createHeader();
            requestHeaders.put("Cookie",taobaoAccount.getCookies());
            JSONObject tokenInfo = new JSONObject();
            tokenInfo.put("token",taobaoAccount.getsId());
            tokenInfo.put("tokenType","taoTVsso");
            tokenInfo.put("clientIp","10.0.8.1");
            tokenInfo.put("site","0");
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("riskControlInfo","{}");
            jsonObject.put("ext","{}");
            jsonObject.put("tokenInfo",tokenInfo.toJSONString());
            String loginResult = OkHttpUtils.postForm(url+"?data="+URLEncoder.encode(jsonObject.toJSONString(),"UTF-8"), requestHeaders, String.class);
            System.out.println(loginResult);
            //处理登陆成功的数据
            String cookies = getCookies(loginResult);
            taobaoAccount.setCookies(cookies);
            taobaoAccount.setExpiredTime(JsonUtil.getJsonValue(loginResult,"data.returnValue.data.expires"));
            taobaoAccount.setUId(JsonUtil.getJsonValue(loginResult,"data.returnValue.data.userId"));
            taobaoAccount.setNickName(JsonUtil.getJsonValue(loginResult,"data.returnValue.taobaoNick"));
            taobaoAccountRepository.save(taobaoAccount);
        }catch (Exception e){
            e.printStackTrace();
            log.error("发生错误,错误信息为{}",e.getMessage());
        }
        return taobaoAccount;
    }
    //组装cookies
    private String  getCookies(String loginResult) {
        String dataStr= JsonUtil.getJsonValue(loginResult,"data.returnValue.data");
        String cookies= TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[7]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[8]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[9]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[10]]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[17]]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[18]]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[20]]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[21]]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[22]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[23]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[24]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[25]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[26]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[27]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[28]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[29]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[30]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[31]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[32]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[34]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[35]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[36]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[35]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[36]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[37]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[38]"),"!",";")+";";
        cookies=cookies+TextUtil.getSubString("!"+JsonUtil.getJsonValue(dataStr,"cookies[39]"),"!",";")+";";
        return cookies;
    }

    private void sendMessage(String content){
      try {
          String url="http://"+ip+":"+port;
          HashMap<String, String> paramHashMap = new HashMap<>();
          paramHashMap.put("data", URLEncoder.encode(content,"UTF-8"));
          String result = OkHttpUtils.postForm(url,null, paramHashMap, String.class);
          System.out.println(result);
      }catch (Exception e){
          e.printStackTrace();
          log.error("发生错误,错误信息为{}",e.getMessage());
      }
    }
}
